home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / CIO.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  3KB  |  135 lines

  1. ;D. Johnson's example character device driver
  2. ;Device "CHARIO" invokes console/screen I/O
  3. ;(This isn't a "useful" device, but illustrative.)
  4. ;Example invocations: COPY CON CHARIO
  5. ; or  COPY CHARIO CON  (don't forget ^Z to end each)
  6.     expand-
  7.     org    0    ;start address (not 100h)
  8. da    macro a1,a2,a3,a4,a5,a6,a7,a8 ;define address(es)
  9.     dw    offset a1
  10.   ifn type(a2)=type()
  11.     da    a2,a3,a4,a5,a6,a7,a8 ;recursively
  12.   endif
  13.  endm ;da
  14. ;****** Driver header follows ***************
  15.     dw    -1,-1    ;next pointer (system modified)
  16.     dw    8000h    ;char device only attribute
  17.     da    strat    ;strategy entry
  18.     da    intr    ;interrupt entry
  19.     db    'CHARIO  ' ;device name (all CAPS)
  20. ;******** Data for INTR follows *************
  21. req    dw    0,0    ;holds request pointer
  22. ftab    da    init    ;func 0 entry address
  23.     da    err,err,err ;func 1-3 illegal
  24.     da    read    ;func 4
  25.     da    err,err,err ;func 5-7
  26.     da    write    ;func 8
  27.     da    err,err,err,err ;func 9-12
  28. f4m    db    'Input char: $' ;func 4 prompt
  29. f8m    db    'Out = '    ;func 8 label
  30. chr    db    0,13,10,'$' ;holds display character 
  31. ;******* Code starts here *****************    
  32. strat    proc    far    ;save request pointer
  33.     seg    cs    ;ds unknown
  34.     mov    req,bx    ;pointer offset
  35.     seg    cs
  36.     mov    req+2,es ;pointer segment
  37.     ret
  38.   endp ;strat
  39. ;******* INTR processing routine *********
  40. intr    proc    far    ;process command
  41.     push    ds    ;save regs
  42.     push    es
  43.     push    ax
  44.     push    dx    ;save bx & cx if modified
  45.     push    si
  46.     push    di
  47.     seg    cs    ;REQ in CS
  48.     lds    si,req    ;load DS & SI from REQ    
  49.     mov    al,[si+2] ;command
  50.     cbw
  51.     shl    al    ;displacement in table
  52.     xchg    ax,di
  53. ;DS:SI points to data header in INTR procedure
  54.     seg    cs    ;FTAB in CS
  55.     call near [di+offset ftab] ;do function
  56.     or    [si+3],ax ;set status from ax
  57.     pop    di    ;restore regs
  58.     pop    si
  59.     pop    dx
  60.     pop    ax
  61.     pop    es
  62.     pop    ds
  63.     ret
  64.   endp ;intr
  65. ;********** function subroutines *********
  66. err    proc    near    ;return illegal func
  67.     mov    ax,8103h ;error done - unknown
  68.     ret        ;to restore
  69.  endp ;err
  70. read    proc    near    ;read & display a char
  71.     mov    dx,offset f4m
  72.     call    disp
  73.     mov    ah,0
  74.     int    16h    ;get a char (BIOS call)
  75.     mov word [si+18],1 ;count = 1
  76.     les    di,[si+14] ;es:di = address
  77.     stosb        ;store data byte
  78.     seg    cs
  79.     mov    chr,al
  80.     mov    dx,offset chr
  81.     call    disp    ;display char & end line
  82.     mov    ax,100h    ;done status
  83.     ret
  84.   endp ;read
  85. write    proc    near    ;display a char
  86.     les    di,[si+14] ;address of data
  87.     seg    es
  88.     mov    al,[di]    ;get byte
  89.     seg    cs
  90.     mov    chr,al    ;store it for output
  91.     mov    dx,offset f8m
  92.     call    disp    ;display message & char
  93.     mov    ax,100h    ;done status
  94.     ret
  95.   endp ;write    
  96. disp    proc    near    ;display a string @CS:DX
  97.     push    ds
  98.     push    cs
  99.     pop    ds    ;to driver seg
  100.     mov    ah,9
  101.     int    21H    ;string output
  102.     pop    ds
  103.     ret
  104.   endp ;disp
  105. ;**** start of free area after initializing ***
  106. init    proc near ;called upon loading
  107.     mov    dx,offset f0m
  108.     call    disp    ;display message
  109.     mov word [si+14],offset init ;first free
  110.     mov    [si+16],cs ;seg of free
  111. ;The following illustrates parameter access
  112.     push    ds
  113.     push    si
  114.     lds    si,[si+18] ;byte following "="
  115.     xor    di,di
  116.     mov    ax,0b000h ;monochrome start
  117.     mov    es,ax
  118.     pushf
  119.     cld
  120.     lodsb        ;get parameter char
  121. lp    es:
  122.     mov    [di+8000h],al ;CGA video
  123.     stosb        ;to mono video
  124.     inc    di    ;skip attribute
  125.     lodsb        ;next char
  126.     cmp    al,13    ;End of line?
  127.     jne    lp
  128.     popf
  129.     pop    si
  130.     pop    ds
  131.     mov    ax,100h    ;done status
  132.     ret
  133.   endp ;init
  134. f0m    db    'Installing CHARIO driver',13,10,'$'
  135.